# Maintainer: Martell Malone <martellmalone@gmail.com>

_realname=v8

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.27.34
pkgrel=1
pkgdesc="Fast and modern Javascript engine (mingw-w64)"
arch=('any')
url="http://code.google.com/p/v8"
license=("BSD")
makedepends=("gyp-svn")
depends=("${MINGW_PACKAGE_PREFIX}-readline")
options=('!emptydirs !strip')
source=("https://github.com/v8/v8/archive/${pkgver}.tar.gz")
md5sums=('b75b5a0308cd0a03309f5bf7b26aa9da')

prepare() {
  cd ${srcdir}/v8-${pkgver}

  #patch -p1 -i ${srcdir}/intrins.patch
  msg 'fixing for python2 name'
  #find -type f -exec sed -e 's_^#!/usr/bin/env python$_&2_' -e 's_^\(#!/usr/bin/python2\).[45]$_\1_' -e 's_^#!/usr/bin/python$_&2_' -e "s_'python'_'python2'_" -i {} \;
  find test -type f -exec sed -e "s|python |python2 |" -i {} \;
  sed -i "s|python |python2 |" Makefile
}

build() {

  export PYTHON=/usr/bin/python2

  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  #cd "${srcdir}/build-${MINGW_CHOST}"

  case ${CARCH} in
    i686)
      _arch=x32
    ;;
    x86_64)
      _arch=x64
    ;;
  esac
  cd "${srcdir}/v8-${pkgver}"
  $PYTHON build/gyp_v8 \
    -Dv8_target_arch=${_arch} \
    -Dcomponent=shared_library \
    -Dsoname_version=${pkgver} \
    -Dv8_enable_i18n_support=false \
    --generator-output=out \
    -f make

  #make dependencies
  make -C out builddir="${srcdir}/build-${MINGW_CHOST}"
}

package() {
  cd "${srcdir}/v8-${pkgver}"
  make install DESTDIR="${pkgdir}" builddir="${srcdir}/build-${MINGW_CHOST}"
}
